<?php
define('ROOT_PATH','../');
define('TEMPLATE_DIR','gmer/');
require_once(ROOT_PATH.'code/bean/config.inc.php');
require_once(ROOT_PATH.'code/class/gmer/class.admin_user.php');
require_once(ROOT_PATH.'code/bean/smarty.config.inc.php');
require_once(ROOT_PATH.'code/bean/db_config.inc.php');
$user=new gmer_user();
$session=check_login('admin/index.php');

$url=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
setcookie('cs_return_url',$url,time()+360000,'/');

$session=check_login('admin/index.php');
if($user->session) {
	
	//按时间查询
	if(isset($_GET['b1']) && $_GET['time1']!='') {
		$t1=$_GET['time1'];
		$t2=$_GET['time2'];
		if($t2=='') $t2=$t1;
		$tmp=explode(' ',$t1);
		$t1='';
		foreach ($tmp as $value) {
			if($value!=' ') {
				if($t1!='') $t1.='-';
				$t1.=$value;
			}
		}
		$tmp=explode(' ',$t2);
		$t2='';
		$c=1;
		foreach ($tmp as $value) {
			if($value!=' ') {
				if($t2!='') $t2.='-';				
				if($c==3) $value++;
				$t2.=$value;
				$c++;
			}
		}
		$sql_where=" ask_time>='$t1' and ask_time<='$t2' ";
		
	}
	//按单据号
	if(isset($_GET['b2']) && $_GET['nb']!='') {
		$nb=$_GET['nb'];
		$sql_where=" id='$nb' ";
	}
	//按处理人
	if(isset($_GET['b3']) && $_GET['gm']!='') {
		$gm=trim($_GET['gm']);
		$sql="select id from gm_user where gm_name='$gm'";
		$res=sql_get_one($sql,__LINE__);
		$gm_id=($res['id'])?$res['id']:-1;
		$sql_where=" gm_id=$gm_id ";
	}
	//按用户
	if(isset($_GET['b4']) && $_GET['user']!='') {
		$user_name=trim($_GET['user']);
		$sql="select id from user_info where nick_name='$user_name' or user_name='$user_name'";
		$res=sql_get_one($sql,__LINE__);
		$user_id=($res['id'])?$res['id']:-1;
		$sql_where=" user_id=$user_id ";
	}
	//总查询
	if(isset($_GET['ba'])) {
		
	}

	if(isset($sql_where)) {
		$sql="select solution_flag,question_info.id,question_info.title,question_info.ask_time,question_class.title from question_info,question_class where ".$sql_where." and question_info.class_id=question_class.class_id order by ask_time desc";
		$ques_list=sql_get_arr($sql,__LINE__);
		if(!$ques_list) $ques_list['sql']['count']='0';
		for ($i=0;$i<$ques_list['sql']['count'];$i++){
			switch ($ques_list[$i]['solution_flag']) {
				case 0:
					$ques_list[$i]['state']='未解决';
					break;
				case 1:
					$ques_list[$i]['state']='已解决';
					break;
				case 2:
					$ques_list[$i]['state']='处理中';
					break;
				case 3:
					$ques_list[$i]['state']='高级gm处理中';
					break;
				case 4:
					$ques_list[$i]['state']='等待质检';
					break;

				default:
					$ques_list[$i]['state']='未知';
					break;
			}			
		}	
		$tpl->assign('ques_list',$ques_list);	
	}
	$tpl->assign('POST',$_GET);
	$tpl->assign('user',$user);	
	$tpl->assign('file_gm_info','tpl/gm_user_info.tpl');
	$tpl->display('op_base_search.html');
}else {
	$tpl->display('gm_login.html');
}
?>